package lambda.demo01;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Mr.ma
 * @since 2022/11/3 18:45
 * 通过lambda自定义比较器
 **/
public class TestComparator {
    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();
        list.add(new Student("张三", 33));
        list.add(new Student("李四", 14));
        list.add(new Student("王五", 25));
        list.add(new Student("赵六", 6));
        list.add(new Student("田七", 17));
        for (Student student : list) {
            System.out.println("student = " + student);
        }
        System.out.println("=========手动分割线=========");
        Collections.sort(list,(s1,s2)->s1.getAge()-s2.getAge());
        for (Student student : list) {
            System.out.println("student = " + student);
        }
    }
}
